package com.demo.juc.blockqueue;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * @Author: shubin_yao
 * @Date: 2022/05/02/22:29
 * @Description:
 *
 * 1、为什么用阻塞队列：
 * 不需要关系什么时候阻塞线程，什么时候需要唤醒线程，这些交给阻塞队列
 *
 * 2、
 *
 *
 */
public class LinkBlockQueueDemo {

    public static void main(String[] args) {
        BlockingDeque<String> blockingDeque = new LinkedBlockingDeque<>(3);

        //抛异常
        blockingDeque.add("a");
        blockingDeque.add("b");
        blockingDeque.add("c");

        blockingDeque.remove("a");
        blockingDeque.remove("b");
        blockingDeque.remove("c");
        //blockingDeque.add("x");
        //System.out.println(blockingDeque.element());


        //
        blockingDeque.offer("a");
        blockingDeque.offer("b");
        blockingDeque.offer("c");
        System.out.println(blockingDeque.offer("x"));  //null

        blockingDeque.poll();
        blockingDeque.poll();
        blockingDeque.poll();
        System.out.println(blockingDeque.peek()); //null

    }
}
